using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 团队实体
    /// 用于表示系统中的团队组织结构，支持多租户隔离
    /// </summary>
    [Table("teams")]
    public class Team : ITenantEntity
    {
        /// <summary>
        /// 团队标识符
        /// </summary>
        [Key]
        public long Id { get; set; }

        /// <summary>
        /// 租户ID
        /// 用于多租户数据隔离
        /// </summary>
        [Required]
        [StringLength(50)]
        public string TenantId { get; set; } = string.Empty;
        
        /// <summary>
        /// 团队名称
        /// 团队的显示名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public string Name { get; set; } = string.Empty;
        
        /// <summary>
        /// 团队代码
        /// 团队的唯一标识代码
        /// </summary>
        [StringLength(50)]
        public string? Code { get; set; }
        
        /// <summary>
        /// 团队描述
        /// 对团队职能和目标的详细说明
        /// </summary>
        [Column(TypeName = "text")]
        public string? Description { get; set; }
        
        /// <summary>
        /// 团队负责人ID
        /// </summary>
        public long? LeaderId { get; set; }
        
        /// <summary>
        /// 关联部门ID
        /// </summary>
        public long? DepartmentId { get; set; }
        
        /// <summary>
        /// 团队类型
        /// 如：项目组、工作组、临时团队等
        /// </summary>
        [StringLength(50)]
        public string? Type { get; set; }
        
        /// <summary>
        /// 团队状态
        /// 0=解散, 1=活跃, 2=暂停, 3=筹建中
        /// </summary>
        public byte Status { get; set; } = 1;
        
        /// <summary>
        /// 最大成员数
        /// </summary>
        public int? MaxMembers { get; set; }
        
        /// <summary>
        /// 排序权重
        /// </summary>
        public int SortOrder { get; set; } = 0;
        
        /// <summary>
        /// 成立时间
        /// </summary>
        public DateTime? EstablishedAt { get; set; }
        
        /// <summary>
        /// 解散时间
        /// </summary>
        public DateTime? DisbandedAt { get; set; }
        
        /// <summary>
        /// 备注信息
        /// </summary>
        [Column(TypeName = "text")]
        public string? Remark { get; set; }
        
        /// <summary>
        /// 创建人ID
        /// </summary>
        public long? CreatedBy { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

        // 导航属性
        /// <summary>
        /// 团队负责人导航属性
        /// </summary>
        [ForeignKey(nameof(LeaderId))]
        public User? Leader { get; set; }
        
        /// <summary>
        /// 关联部门导航属性
        /// </summary>
        [ForeignKey(nameof(DepartmentId))]
        public Department? Department { get; set; }
        
        /// <summary>
        /// 创建人导航属性
        /// </summary>
        [ForeignKey(nameof(CreatedBy))]
        public User? Creator { get; set; }
        
        /// <summary>
        /// 团队成员关联集合
        /// </summary>
        [InverseProperty(nameof(TeamMember.Team))]
        public ICollection<TeamMember> TeamMembers { get; set; } = new List<TeamMember>();
    }
}
